import sys
from spritemaker.parser import Parse
from optparse import OptionParser

def main():
    parser = OptionParser(
        usage="usage: %prog [options] spritefile",
        description="""Eases the process of maing css sprites. You can pass in
a sprite definition file, and get out rules for css sprites.
        """)
    parser.add_option("-o", "--out", dest="outimage",
                      help="writes the image output to FILE", metavar="FILE")

    parser.add_option("--html", dest="outhtml",
                      help="writes example html output to FILE", metavar="FILE")

    (options, args) = parser.parse_args()

    if len(args) != 1:
        parser.error("need to pass an input file")
    
    b = Parse (args[0])
    
    b.ValidateLayout ()

    if options.outimage:
        img = b.Draw ()
        img.save (options.outimage)

    if options.outhtml:
        if not options.outimage:
            parser.error ("need an out image for the html")

        open (options.outhtml, 'w').write (b.HtmlDemo (options.outimage))

        
